package com.atguigu.protoType.deepClone;

/**
 * @program: design-patterns
 * @author: yangshen
 * @description: 深拷贝 客户端
 * @create: 2022-02-10 11:21
 **/
public class Client {
    public static void main(String[] args) throws CloneNotSupportedException {
        DeepProtoType p = new DeepProtoType();
        p.name = "宋江";
        p.deepCloneableTarget = new DeepCloneableTarget("大牛", "大牛的类");
        //先打印自身的引用属性（对象）哈希值
        System.out.println("p.name = " + p.name + ", p.deepCloneableTarget = " + p.deepCloneableTarget.hashCode());

        System.out.println("---------------------方式1-----------------------------------");

        //方式1 完成深拷贝（clone方法）
        DeepProtoType p2 =(DeepProtoType) p.clone();
        //1.1 p.deepCloneableTarget.hashCode() != p2.deepCloneableTarget.hashCode(), 深拷贝成功
        System.out.println("p2.name = " + p2.name + ", p2.deepCloneableTarget = " + p2.deepCloneableTarget.hashCode());

        System.out.println("---------------------方式2-----------------------------------");

        //方式2 完成深拷贝（序列化方法）
        DeepProtoType p3 =(DeepProtoType) p.deepClone();
        System.out.println("p3.name = " + p3.name + ", p3.deepCloneableTarget = " + p3.deepCloneableTarget.hashCode());


    }
}
